package org.example.cake.service.impl;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.example.cake.mapper.FestivalMapper;
import org.example.cake.entity.Festival;
import org.example.cake.service.FestivalService;

import java.util.List;
import java.util.Map;

@Service
public class FestivalServiceImpl implements FestivalService{

    @Resource
    private FestivalMapper festivalMapper;

    @Override
    public int deleteByPrimaryKey(Integer festivalid) {
        return festivalMapper.deleteByPrimaryKey(festivalid);
    }

    @Override
    public int insert(Festival record) {
        return festivalMapper.insert(record);
    }

    @Override
    public int insertSelective(Festival record) {
        return festivalMapper.insertSelective(record);
    }

    @Override
    public Festival selectByPrimaryKey(Integer festivalid) {
        return festivalMapper.selectByPrimaryKey(festivalid);
    }

    @Override
    public int updateByPrimaryKeySelective(Festival record) {
        return festivalMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Festival record) {
        return festivalMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Festival> getFestivals() {
        return festivalMapper.getFestivals();
    }

    /**
     * //后台节日活动分页模糊查询
     * @author 徐
     * @param festivalname 节日名称
     * @date 2025-07-31
     * @return 节日集合
     */
    @Override
    public List<Festival> selectFestivalPageEnd(@Param("festivalname") String festivalname,
                                                @Param("discountid") Integer discountid) {
        return festivalMapper.selectFestivalPageEnd(festivalname,discountid);
    }

    /**
     * //后台节日活动删除（根据id删除）
     * @author 徐
     * @param festivalid 节日id
     * @date 2025-07-31
     * @return 节日id
     */
    @Override
    public String deleteFestivalEnd(Integer festivalid) {
        return festivalMapper.deleteFestivalEnd(festivalid)>0?"删除成功":"删除失败";
    }

    /**
     * //新增后台节日活动信息
     * @author 徐
     * @param festival 节日对象
     * @date 2025-07-31
     * @return 受影响的行数
     */
    @Override
    public String insertFestivalEnd(Festival festival) {
        return festivalMapper.insertFestivalEnd(festival)>0?"新增成功":"新增失败";
    }

    /**
     * //修改后台节日信息
     * @author 徐
     * @param festival 节日对象
     * @date 2025-07-31
     * @return 受影响的行数
     */
    @Override
    public String updateFestivalEnd(Festival festival) {
        return festivalMapper.updateFestivalEnd(festival)>0?"修改成功":"修改失败";
    }

    @Override
    public List<Festival> selectAllFestivalSky() {
        return festivalMapper.selectAllFestivalSky();
    }

    @Override
    public List<Map<String, Object>> selectAvailableDiscountSky() {
        return festivalMapper.selectAvailableDiscountSky();
    }

    @Override
    public Festival selectByPrimaryKeySky(Integer festivalid) {
        if (festivalid == null) {
            throw new IllegalArgumentException("活动ID不能为空");
        }
        return festivalMapper.selectByPrimaryKeySky(festivalid);
    }

    @Override
    public int insertFestivalSky(Festival festival) {
        return festivalMapper.insertFestivalSky(festival);
    }

    @Override
    public int updateFestivalSky(Festival festival) {
        return festivalMapper.updateFestivalSky(festival);
    }

    @Override
    public int deleteFestivalSky(Integer festivalid) {
        return festivalMapper.deleteFestivalSky(festivalid);
    }

    @Override
    public List<Festival> selectFestivalsByDiscountId(Integer discountid) {
        return festivalMapper.selectCurrentFestivalSky();
    }
    /**
     * //后台根据id查询节日活动是否存在
     * @author 徐
     * @param festivalid 节日id
     * @date 2025-08-04
     * @return 受影响行数
     */
    @Override
    public Festival selectById(Integer festivalid) {
        return festivalMapper.selectById(festivalid);
    }

}
